package com.ouman.pure.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * Created by jintian on 14/04/2017.
 */

public class NetworkHelper {

    // judge is there is data connection not include wifi
    public static boolean isDataConnectionAvailable(Context context) {
        ConnectivityManager connectivityManager =
                (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
        return activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting();
    }

    //judge is there is network connection, include wifi and data connection
    public static boolean isConnect(Context context) {
        boolean flag = false;

        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivityManager.getActiveNetworkInfo() != null){
            flag = connectivityManager.getActiveNetworkInfo().isAvailable();
        }
        return flag;
    }
}
